package com.relytosoft.mizar.media.camera.api.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.relytosoft.dubhe.common.core.base.BaseEntity;
import com.relytosoft.mizar.media.camera.api.pojo.dto.VideoRecordDto;
import com.relytosoft.mizar.media.common.entity.pojo.dto.AlarmDto;
import com.relytosoft.mizar.media.common.enums.ResourceTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * @author wss
 * @version 1.0
 * @date 2022/6/8 10:28
 */
@TableName("VID_MULTIMEDIA")
@ApiModel("Multimedia")
public class Multimedia extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键", required = true)
    @TableField("ID")
    @NotNull(message = "主键不能为空")
    private Integer id;

    @ApiModelProperty(value = "资源类型")
    @TableField("RESOURCE_TYPE")
    private Integer resourceType;

    @ApiModelProperty(value = "记录时间")
    @TableField("RECORD_TIME")
    private LocalDateTime recordTime;

    @ApiModelProperty(value = "设备id")
    @TableField("DEVICE_ID")
    private String deviceId;

    @ApiModelProperty(value = "资源url")
    @TableField("RESOURCE_URL")
    private String resourceUrl;

    @ApiModelProperty(value = "备注")
    @TableField("REMARK")
    private String remark;

    @ApiModelProperty(value = "状态", required = true)
    @TableField("STATUS")
    private Integer status;

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public static Multimedia buildVideoObject(String url, VideoRecordDto videoRecordDto) {
        Multimedia multimedia = new Multimedia();
        multimedia.setResourceUrl(url);
        multimedia.setResourceType(videoRecordDto.getResourceTypeEnum().getValue());
        multimedia.setDeviceId(videoRecordDto.getDeviceId().toString());
        return multimedia;
    }

    public Integer getResourceType() {
        return resourceType;
    }

    public LocalDateTime getRecordTime() {
        return recordTime;
    }

    public void setRecordTime(LocalDateTime recordTime) {
        this.recordTime = recordTime;
    }

    public static Multimedia buildMultimedia(AlarmDto alarmDto, ResourceTypeEnum resourceTypeEnum) {
        Multimedia multimedia = new Multimedia();
        multimedia.setDeviceId(alarmDto.getCameraId());
        multimedia.setResourceUrl(Optional.ofNullable(alarmDto.getAlarmImg()).orElse(alarmDto.getAlarmVideo()));
        multimedia.setRecordTime(alarmDto.getAlarmTime());
        multimedia.setRemark(alarmDto.getRemark());
        multimedia.setResourceType(resourceTypeEnum.getValue());
        return multimedia;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public String getResourceUrl() {
        return resourceUrl;
    }

    public void setResourceUrl(String resourceUrl) {
        this.resourceUrl = resourceUrl;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setResourceType(Integer resourceType) {
        this.resourceType = resourceType;
    }

    @Override
    public String toString() {
        return "Multimedia{" +
                "id=" + id +
                ", resourceType=" + resourceType +
                ", recordTime=" + recordTime +
                ", deviceId=" + deviceId +
                ", resourceUrl='" + resourceUrl + '\'' +
                ", remark='" + remark + '\'' +
                ", status=" + status +
                '}';
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

}
